package com.ghsc.ghxc.jsb.ui.mall.activity

import com.cn.appcore.base.BaseVMActivity
import com.cn.appcore.ext.setSingleClickListener
import com.ghsc.ghxc.jsb.R
import com.ghsc.ghxc.jsb.databinding.ActivityVideoPlayerBinding
import com.ghsc.ghxc.jsb.ext.intentExtras
import xyz.doikki.videoplayer.player.VideoView

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.mall.activity
 * 类名：VideoPlayerActivity
 * 创建时间：2024/5/17 14:18
 * 创建人 @author： xiaolin
 * 描述 ：Todo... 视频播放
 */
class VideoPlayerActivity  : BaseVMActivity<VideoPlayerViewModel, ActivityVideoPlayerBinding>() {

    private val videoPath: String? by intentExtras("video_path")

    override fun attachVMClass(): Class<VideoPlayerViewModel>? {
        return VideoPlayerViewModel::class.java
    }

    override fun attachLayoutRes(): Int {
        return R.layout.activity_video_player
    }

    override fun initView() {
        binding.apply {
            videoView.setUrl(videoPath)
            videoView.setScreenScaleType(VideoView.SCREEN_SCALE_CENTER_CROP)
            videoView.setLooping(true)
            videoView.start()
        }
        binding.ivBack.setSingleClickListener {
            finish()
        }
    }

    override fun onResume() {
        super.onResume()
        binding.videoView.resume()
    }

    override fun onPause() {
        super.onPause()
        binding.videoView.pause()
    }

    override fun onBackPressed() {
        if (!binding.videoView.onBackPressed()) {
            super.onBackPressed();
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        binding.videoView.release()
    }

}

